package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.stuinfo.domain.StudentPunishments;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.StudentRewards;
import com.ruoyi.stuinfo.service.IStudentRewardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 获奖查询Controller
 *
 * @author zc
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/stuinfo/rewards")
public class StudentRewardsController extends BaseController
{
    @Autowired
    private IStudentRewardsService studentRewardsService;

    /**
     * 查询获奖查询列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:rewards:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentRewards studentRewards)
    {

        String teacherId = getUsername();

        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<StudentRewards> list = studentRewardsService.selectStudentRewardsList(studentRewards);
            return getDataTable(list);
        }
        else
        {
            //学生
            startPage();
            List<StudentRewards> list = studentRewardsService.selectStudentRewardsList_stuednt(teacherId);
            return getDataTable(list);
        }
    }

    /**
     * 导出获奖查询列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:rewards:export')")
    @Log(title = "获奖查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentRewards studentRewards)
    {

        String teacherId = getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            List<StudentRewards> list = studentRewardsService.selectStudentRewardsList(studentRewards);
            ExcelUtil<StudentRewards> util = new ExcelUtil<StudentRewards>(StudentRewards.class);
            util.exportExcel(response, list, "获奖查询数据");
        }
        else
        {
            //学生
            List<StudentRewards> list = studentRewardsService.selectStudentRewardsList_stuednt(teacherId);
            ExcelUtil<StudentRewards> util = new ExcelUtil<StudentRewards>(StudentRewards.class);
            util.exportExcel(response, list, "获奖查询数据");
        }
    }

    /**
     * 获取获奖查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:rewards:query')")
    @GetMapping(value = "/{rewardId}")
    public AjaxResult getInfo(@PathVariable("rewardId") Long rewardId)
    {
        return success(studentRewardsService.selectStudentRewardsByRewardId(rewardId));
    }

    /**
     * 新增获奖查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:rewards:add')")
    @Log(title = "获奖查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentRewards studentRewards)
    {
        return toAjax(studentRewardsService.insertStudentRewards(studentRewards));
    }

    /**
     * 修改获奖查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:rewards:edit')")
    @Log(title = "获奖查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentRewards studentRewards)
    {
        return toAjax(studentRewardsService.updateStudentRewards(studentRewards));
    }

    /**
     * 删除获奖查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:rewards:remove')")
    @Log(title = "获奖查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rewardIds}")
    public AjaxResult remove(@PathVariable Long[] rewardIds)
    {
        return toAjax(studentRewardsService.deleteStudentRewardsByRewardIds(rewardIds));
    }
}
